package com.chuanye.mydrawable.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.chuanye.mydrawable.R;
import com.chuanye.mydrawable.beans.City;

import java.util.List;

/**
 * Created by lsef on 2019/1/15.
 */

public class SpinnerTwoAdapter extends BaseAdapter{
    private Context mContext;
    private List<City.CityBean.CountyBean> countyBeanList;

    public SpinnerTwoAdapter(Context mContext, List<City.CityBean.CountyBean> countyBeanList) {
        this.mContext = mContext;
        this.countyBeanList = countyBeanList;
    }

    @Override
    public int getCount() {
        return countyBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return countyBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null){
            view = View.inflate(mContext, R.layout.spinner_two_item,null);
            holder = new ViewHolder();
            holder.name = view.findViewById(R.id.spinner_two_name);
            holder.number = view.findViewById(R.id.spinner_two_number);

            view.setTag(holder);
        }
        holder = (ViewHolder) view.getTag();
        holder.name.setText(countyBeanList.get(i).getName());
        holder.number.setText(countyBeanList.get(i).getNumber());


        return view;
    }

    private static class ViewHolder{
        TextView name;
        TextView number;

    }
}
